<?php

@$shop_id = $_REQUEST['function'];
@$item_from_url = $_REQUEST['v2'];
@$quantity = $_REQUEST['v3'];
$shop = new shop_class($shop_id);

$shop_name = $shop->info['name'];

echo "<h1>$shop_name</h1>";

    
echo '<p>';
echo "Welcome to <B>$shop_name</B>.";
echo '</p>';



if (@$_REQUEST['v1'] == 'buy')
{
	$item_info = $db->return_first_result("SELECT * FROM `user_business_market` WHERE `business_id`='$shop_id' AND `buy_or_sell`='buy' AND `item`='$item_from_url'");
	//display_var($item_info);
	get_item(USER_ID,$item_info['item'],$quantity,$item_info['section'],$item_info['type'],$item_info['exp'],$item_info['quality'], $shop_name);
	echo '<pre>Item Bought</pre>';
}



# FOR SALE
echo '<h2>Selling</h2><p>';
    
$query = "SELECT * FROM `user_business_market` WHERE `buy_or_sell`='sell' AND `business_id`='$shop_id'";
$result = $db->query($query);

while ($row = $result->fetch_object()) 
{
	switch ($row->section)
	{
		
		
		case 'gladiator':
			$link_1 = ahref("/shop/$shop_id/buy/$row->item/1/",'Purchase 1');
			if (strlen($row->cache_name) < 1)
			{
				$item_name = gladiator_item_lookup($row->item);
			}
			else 
			{
				$item_name = $row->cache_name;
			}
			echo "<br>We sell &quot;$item_name&quot; for ".$row->price."z [$link_1]";
			break;
			
			
			
			
			
		default:
			$link_1 = ahref("/shop/$shop_id/buy/$row->item/1/",'Purchase 1');
			if (strlen($row->cache_name) < 1)
			{
				$item_name = $row->item;
			}
			else 
			{
				$item_name = $row->cache_name;
			}
			echo "<br>We sell &quot;$item_name&quot; for ".$row->price."z [$link_1]";
			break;
	}
	
}






# WE BUY
echo '</p><h2>Buying</h2><p>';

$query = "SELECT * FROM `user_business_market` WHERE `buy_or_sell`='buy' AND `business_id`='$shop_id'";
$result = $db->query($query);

while ($row = $result->fetch_object()) 
{
	$link_1 = ahref("/shop/$shop_id/sell/$row->item/1/",'Sell 1');
	echo "<br>We buy &quot;$row->item&quot; for ".$row->price."z [$link_1]";
}

echo '</p>';



/*switch (@$_REQUEST['function'])
{
	case 'shops':
		echo 'stalls';
		break;
	default:
		break;
}*/

?>